#pragma once
#include "ContextSession.h"
#include <list>
#include "pool.hpp"

class CCompletionPortServer;

// SessionManager
class CSessionManager
{
public:
    CSessionManager()
    {
    }

    ~CSessionManager()
    {
    }
    void Remove(CContextSessionPtr& client)
    {
        for (auto it = clients_.begin(); it != clients_.end(); ++it)
        {
            if (*it == client)
            {
                clients_.erase(it);
                break;
            }
        }
    }
    void Remove(CContextSession* client)
    {
        for (auto it = clients_.begin(); it != clients_.end(); ++it)
        {
            if ((*it).get() == client)
            {
                clients_.erase(it);
                break;
            }
        }
    }
    void RemoveAll()
    {
        clients_.clear();
    }
    size_t GetCount()
    {
        return clients_.size();
    }
    void Add(CContextSessionPtr& client)
    {
        clients_.push_back(client);
    }
    // test
    int PostSend(const char* buf, int len, CCompletionPortServer* server);
private:

    std::list<CContextSessionPtr> clients_;
};
